#include "RingQueue.hpp"
#include <ctime>

void* producer(void* ring_queue)
{
  RingQueue<int>* rq = (RingQueue<int>*)ring_queue;
  while(true)
  {
    //生产
    int in = rand() % 20 + 1;
    rq->Put(in);
    std::cout << "producer put " << in << std::endl;
  }
  return nullptr; 
}
void* consumer(void* ring_queue)
{
  RingQueue<int>* rq = (RingQueue<int>*)ring_queue;
  while(true)
  {
    //消费
    int out = 0;
    rq->Get(&out);
    std::cout << "consumer get " << out << std::endl;
  }
  return nullptr; 
}

int main()
{
  srand((unsigned long)time(nullptr));
  RingQueue<int>* rq = new RingQueue<int>(10);
  pthread_t p, c;
  pthread_create(&p, nullptr, producer, rq);
  pthread_create(&c, nullptr, consumer, rq);

  pthread_join(c, nullptr);
  pthread_join(p, nullptr);
  return 0;
}
